package com.example.shop_2208.adapter

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.shop_2208.R
import com.example.shop_2208.entity.CategoryEntity

class OneAdapter:BaseQuickAdapter<CategoryEntity,BaseViewHolder>(R.layout.item_one) {
    private var selectedId = 1//默认选中的id

    override fun convert(holder: BaseViewHolder, item: CategoryEntity) {
        holder.setText(R.id.cate_one_tv,item.category_name)
        holder.getView<TextView>(R.id.cate_one_tv).background =
            if(selectedId==item.id){
            ColorDrawable(Color.RED)
        }else null
    }

    fun setSelectedId(id:Int){
        selectedId = id
        notifyDataSetChanged()
    }
}